home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 050 / allfil.arc / ALLFILES.LIB next >
Encoding:
Text File  |  1986-03-09  |  6.9 KB  |  179 lines

  1.   {@@@@@@@@@@@@@@@@@@@ copyright 1984 by Neil J. Rubenking @@@@@@@@@@@@@@@@@@@
  2.  
  3.   ALLFILES(ulCol, ulRow, lrCol, lrRow : byte;
  4.   VAR template : filename_type;
  5.   VAR error_return : byte);
  6.  
  7.   Pass the UpperLeft and LowerRight corners of the window in which selection
  8.   is to take place and the template (e.g., 'c:\whammy\*.*') of the files to
  9.   be scanned.  Returns the selected filename in "template", or an error code.
  10.   The width of the window must be at least 18 characters--36 gives two columns.
  11.  
  12.   If the user "breaks out" of the selection process by pressing <Esc>, the
  13.   error return code is set to 255.
  14.  
  15.   REQUIRES : filename.typ
  16.   regpack.typ
  17.   getkeys.lib
  18.   monitor.lib
  19.   screen.lib
  20.   getfile.lib
  21.   These files must also be INCLUDEd in a program that uses ALLFILES.
  22.   }
  23.  
  24.   {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
  25.   PROCEDURE Frame(ulC, ulR, lrC, lrR : Byte); { Upper Left and Lower Right
  26.                                               Row and Column }
  27.   VAR
  28.     I : Byte;
  29.   BEGIN
  30.     GoToXY(ulC, ulR); Write(Chr(201));
  31.     FOR I := ulC+1 TO lrC-1 DO Write(Chr(205));
  32.     Write(Chr(187));
  33.     FOR I := ulR+1 TO lrR-1 DO
  34.       BEGIN
  35.         GoToXY(ulC, I); Write(Chr(186));
  36.         GoToXY(lrC, I); Write(Chr(186));
  37.       END;
  38.     GoToXY(ulC, lrR);
  39.     Write(Chr(200));
  40.     FOR i := ulC+1 TO lrC-1 DO Write(Chr(205));
  41.     Write(Chr(188));
  42.   END;
  43.  
  44.  
  45.   {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
  46.   PROCEDURE AllFiles(ulCol, ulRow, lrCol, lrRow : Byte;
  47.                      VAR template : filename_type;
  48.                      VAR error_return : Byte);
  49.   VAR
  50.     OneChar, choice, EscChoice : Char;
  51.     attrib, error, margin, count, HowDeep : Byte;
  52.     {-------------------------------------------------------------------}
  53.     PROCEDURE Do_select(VAR name : filename_type);
  54.     VAR
  55.       N, X, Y, loc : Byte;
  56.       {----------------------------------------------------------}
  57.       PROCEDURE transloc(loc : Byte; VAR X, Y : Byte); { translates a numeric  }
  58.       BEGIN                   { location ("7th file") }
  59.         X := ((loc-1) DIV (howDeep-1))*18+ulCol; { into X and Y coordin- }
  60.         Y := (loc-1) MOD (howDeep-1)+ulRow; { ates and writes a     }
  61.         WriteScreen(X, Y, Chr(16), 112); { pointer at those      }
  62.       END;                    { coordinates.          }
  63.       {----------------------------------------------------------}
  64.     BEGIN
  65.       loc := 1;
  66.       transloc(loc, X, Y);
  67.       GoToXY(X-ulCol+1, Y-ulRow+1); { This line keeps the normal cursor
  68.                                     in the same place as the pointer. }
  69.       REPEAT
  70.         getKeys(choice, EscChoice);
  71.         IF choice = Chr(27) THEN
  72.           BEGIN
  73.             CASE EscChoice OF
  74.               'H' : BEGIN
  75.                       WriteScreen(X, Y, ' ', 15);
  76.                       IF loc > 1 THEN loc := loc-1 ELSE loc := count;
  77.                       transloc(loc, X, Y);
  78.                     END;
  79.               { UP arrrow.  If the LOCation is any but the first, it
  80.               just decrements by one.  If it's the first, it becomes
  81.               the last.  Thus there's a "wrap" effect. }
  82.               'P' : BEGIN
  83.                       WriteScreen(X, Y, ' ', 15);
  84.                       IF loc < count THEN loc := loc+1 ELSE loc := 1;
  85.                       transloc(loc, X, Y);
  86.                     END;
  87.               { DOWN arrow.  Increments LOCation by one.  If already
  88.               at the end, "wraps" to beginning. }
  89.               'K' : BEGIN
  90.                       WriteScreen(X, Y, ' ', 15);
  91.                       IF loc > (howDeep-1) THEN loc := loc-(howDeep-1) ELSE
  92.                         BEGIN
  93.                           loc := loc+5*(howDeep-1);
  94.                           WHILE loc > count DO loc := loc-(howDeep-1);
  95.                         END;
  96.                       transloc(loc, X, Y);
  97.                     END;
  98.               { LEFT arrow.  Moves to same screen line one column to
  99.               the left.  If already at leftmost column, goes to far
  100.               right column. }
  101.               'M' : BEGIN
  102.                       WriteScreen(X, Y, ' ', 15);
  103.                       loc := loc+HowDeep-1;
  104.                       IF loc > count THEN loc := loc MOD (HowDeep-1);
  105.                       IF loc = 0 THEN loc := HowDeep-1;
  106.                       transloc(loc, X, Y);
  107.                     END;
  108.               { RIGHT arrow.  Moves to same screen line one column to
  109.               the right.  If already at rightmost, goes to far left. }
  110.             END;              {case}
  111.             GoToXY(X-ulCol+1, Y-ulRow+1); { Put the normal cursor in the
  112.                                           same place as the pointer.  }
  113.           END;                { if }
  114.       UNTIL (choice = #13) OR ((choice = #27) AND (EscChoice = #0));
  115.       IF choice = #27 THEN error_return := 255;
  116.       name := '';
  117.       { Now we pick the selected name right off the screen. }
  118.       FOR N := 1 TO 13 DO
  119.         BEGIN
  120.           oneChar := ReadScreen(X+N, Y);
  121.           IF NOT(oneChar IN [#0, #32]) THEN name := name+oneChar;
  122.         END;
  123.       Window(ulCol-1, ulRow-2, lrCol+1, lrRow+1);
  124.       ClrScr;
  125.       Window(1, 1, 80, 25);
  126.     END;
  127.     {-------------------------------------------------------------------}
  128.   BEGIN
  129.     GoToXY(ulCol, ulRow-1);
  130.     Write('Move w/ arrows, select w/ <Return>'); HighVideo; ClrEol;
  131.     TextColor(Black); TextBackground(White);
  132.     frame(ulCol-1, ulRow-2, lrCol+1, lrRow+1);
  133.     Window(ulCol, ulRow, lrCol, lrRow);
  134.     HighVideo;
  135.     ClrScr;
  136.     howDeep := lrRow-ulRow;
  137.     attrib := 32;
  138.     buffer.name := '             ';
  139.     Find_First(attrib, template, error);
  140.     error_return := error;
  141.     IF error = 0 THEN
  142.       BEGIN
  143.         count := 1;
  144.         margin := 2;
  145.         GoToXY(margin, WhereY);
  146.         WriteLn(template);
  147.         REPEAT
  148.           buffer.name := '             ';
  149.           find_Next(attrib, template, error);
  150.           IF error = 0 THEN
  151.             BEGIN
  152.               GoToXY(margin, WhereY);
  153.               WriteLn(template);
  154.               count := count+1;
  155.               IF WhereY > HowDeep-1 THEN
  156.                 BEGIN
  157.                   margin := margin+18;
  158.                   GoToXY(margin, 1);
  159.                 END;
  160.               IF count >= ((HowDeep-1)*(((lrCol-ulCol) DIV 18))) THEN
  161.                 BEGIN
  162.                   GoToXY(1, HowDeep);
  163.                   Write('Any key to see more, <CR> to stay');
  164.                   GetKeys(choice, EscChoice);
  165.                   GoToXY(1, HowDeep); ClrEol;
  166.                   IF choice = #13 THEN error := 1
  167.                   ELSE
  168.                     BEGIN
  169.                       ClrScr;
  170.                       count := 0;
  171.                       margin := 2;
  172.                     END;
  173.                 END;
  174.             END;
  175.         UNTIL error <> 0;
  176.         do_select(template);
  177.       END;
  178.   END;
  179.